package com.weiweb.dao;

import java.util.List;

import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.weiweb.domain.Task;

public class TaskDaoImpl extends HibernateDaoSupport implements TaskDao {

	public void addTask(Task task) {
		getHibernateTemplate().save(task);
	}
	

	public List<Task> findTaskList() {
		String hql="from Task t left outer join fetch t.user where tasktype='follow' order by cost desc";
		@SuppressWarnings("unchecked")
		List<Task> list=getHibernateTemplate().find(hql);
		return list;
	} 
	
	public static void main(String[] args) {
		//ApplicationContext context = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
		XmlBeanFactory context=new XmlBeanFactory(new ClassPathResource("applicationContext.xml"));
		TaskDao dao = (TaskDao)context.getBean("taskDao");
		dao.findTaskList();
	}

}
